﻿using System;
using System.Data.SqlClient;
using Devv.Core.UniDataTier;

namespace Yglu.BusinessLayer.Entities
{
	public class Product : BaseEntity
	{
		#region Properties

		public Int32 StoreId { get; set; }
		public String Title { get; set; }
		public Double Price { get; set; }
		public Boolean AllStores { get; set; }

		public Category Category { get; set; }

		#endregion

		#region Extra properties

		public String CategoryTitle
		{
			get
			{
				return Category.Title;
			}
		}

		public String FullTitle
		{
			get
			{
				return Category.Title + ": " + Title;
			}
		}

		#endregion

		#region Constructor

		public Product()
		{
			Category = new Category();
		}

		public Product(Int32 id)
		{
			Construct(DataAccess.Product_Get(id));
		}

		public Product(SqlDataReader reader)
		{
			Construct(reader);
		}

		#endregion

		#region Methods

		public override void Load(SqlDataReader reader)
		{
			Id = DataHandler.GetInt32(reader, "ProductId");
			StoreId = DataHandler.GetInt32(reader, "StoreId", 0);
			Title = DataHandler.GetString(reader, "ProductTitle");
			Price = DataHandler.GetDouble(reader, "ProductPrice");
			AllStores = DataHandler.GetBoolean(reader, "ProductAllStores");
			Active = DataHandler.GetBoolean(reader, "ProductActive");

			Category = new Category();
			Category.Load(reader);
		}

		#endregion

		#region ToString

		public new String ToString()
		{
			return Title;
		}

		#endregion
	}
}